﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using cecbData;

namespace CECB.Member
{
    /// <summary>
    /// Interaction logic for V_MemberUpdate_Window.xaml
    /// </summary>
    public partial class V_MemberUpdate_Window : Window
    {
        public V_MemberUpdate_Window()
        {
            InitializeComponent();

           // comboBox_ModifySpecilised.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getSpecializatioInformations();
           // ModifySaveButton.IsEnabled = false;
            autoCompleteBox_SearchMember.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getAllMembers();
            comboBox_ModifySpecilised.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getSpecializatioInformations();

        }

        private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
        {
            Regex regex = new Regex("[^0-9]+");
            e.Handled = regex.IsMatch(e.Text);

        }


        private void Email_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {

        }



        private void button_Save_Cancel_Click(object sender, RoutedEventArgs e)
        {

        }




        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void NewButton_Click(object sender, RoutedEventArgs e)
        {


        }







 




        private void textBox_ContactNo3_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            Regex regex = new Regex("[^0-9]+");
            e.Handled = regex.IsMatch(e.Text);


        }

        private void textBox_ContactNo3_TextChanged(object sender, TextChangedEventArgs e)
        {

        }



        private void Label_SourceUpdated(object sender, DataTransferEventArgs e)
        {

        }
        Members mem = null;
        private void autoCompleteBox_SearchMember_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
             
            if (((AutoCompleteBox)sender).SelectedItem != null)
            {
              mem = (Members)autoCompleteBox_SearchMember.SelectedItem;

              try
              {
                new cecbClasses.Data_Adapters.Member.Func_Members().getMemberDetails(mem.mem_reference);
                new cecbClasses.Data_Adapters.Member.Func_Members().getMemberLoginDetails(mem.mem_reference);

                List<Members> aa = new List<Members>();
                List<MemberLogin> bb = new List<MemberLogin>();
                bb = new cecbClasses.Data_Adapters.Member.Func_Members().getMemberLoginDetails(mem.mem_reference);
                aa = new cecbClasses.Data_Adapters.Member.Func_Members().getMemberDetails(mem.mem_reference);
                textBox_ModifyAddress.Text = aa[0].mem_address;
                textBox_ModifyFirstName.Text = aa[0].mem_name;
                
                comboBox_ModifySpecilised.Text = aa[0].mem_areaOfSpec;
                comboBox_ModifyDesignation.Text = aa[0].mem_designation;

                ModifySaveButton.IsEnabled = true;


            }
            catch (Exception)
            {


            }
        }
     }
        private void updateButton_Click(object sender, RoutedEventArgs e)
        {




            //Members mem = null;
            cecbClasses.Data_Adapters.Member.Func_Members aa = new cecbClasses.Data_Adapters.Member.Func_Members();



            if (autoCompleteBox_SearchMember.SelectedItem == null)
                MessageBox.Show("select a member", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            else
            {
               // comboBox_ModifySpecilised.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getSpecializatioInformations();

                if (aa.updateMemberDetails(mem.mem_reference, textBox_ModifyAddress.Text, textBox_ModifyFirstName.Text, comboBox_ModifyDesignation.Text, comboBox_ModifySpecilised.Text))
                {

                    MessageBox.Show("Member informations Successfully Updated", "Message", MessageBoxButton.OK, MessageBoxImage.Information);


                    //comboBox_ModifySpecilised.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getSpecializatioInformations();
                    //comboBox_ModifyDesignation.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getdesignationInformations();

                    autoCompleteBox_SearchMember.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getAllMembers();
                    clearAfterUpdate();

                }
                else
                {
                    MessageBox.Show("Selected nothing to modify", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
               // comboBox_ModifySpecilised.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getSpecializatioInformations();

                clearAfterUpdate();
                comboBox_ModifySpecilised.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getSpecializatioInformations();


            }
        }
        public void clearAfterUpdate()
        {

            textBox_ModifyFirstName.Clear();
            textBox_ModifyAddress.Clear();
             
            
            comboBox_ModifyDesignation.SelectedIndex = -1;
            comboBox_ModifySpecilised.SelectedIndex = -1;
            autoCompleteBox_SearchMember.Text = "";
            //comboBox_ModifySpecilised.ItemsSource = null;

            //if (comboBox_ModifySpecilised.Items.Count != 0)
            //{
            //    comboBox_ModifySpecilised.Items.Clear();
            //}


        }

        private void textBox_Modifyusername_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void textBox_Modifyusername_SelectionChanged(object sender, RoutedEventArgs e)
        {

        }

        private void textBox_Modifyusername_TextInput(object sender, TextCompositionEventArgs e)
        {

        }

        private void textBox_Modifyusername_IsHitTestVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {

        }

        private void comboBox_Specilised_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void textBoxUpdateContact_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Close();
        }

        private void textBox_Designation_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }


    }
}

